package com.aaa.system.Controller.Api;

import com.aaa.entity.DictData;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.DictDataService;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/api/dict/data")
public class ApiDictDataController {

    @Autowired
    private DictDataService dictDataService;

    /**
     *根据类型查询字典数据
     */
    @GetMapping("findByType/{type}")
    public Result<List<DictData>> list(@PathVariable String type){
        return dictDataService.findByType(type);
    }

    /**
     *根据类型id查询一个字典的类型
     */
    @GetMapping("getDDByDictId")
    public Result<String> getDDByDictId(@RequestParam Long dictId){
        return dictDataService.findDDByDictId(dictId);
    }

    /**
     *查询 分页
     */
    @PostMapping("getTypeData/{current}/{size}")
    public Result<IPage<DictData>> selectTypeData(@PathVariable Long current,@PathVariable Long size,@RequestBody DictData dictData){
        return dictDataService.findAllTypeData(current,size,dictData);
    }
    /**
     * 添加修改
     */
    @PostMapping("saveOrUpdDictData")
    @Log(title = "添加/修改字典类型数据",business_type = "2")
    public Result<Boolean> saveOrUpdDictData(@RequestBody DictData dictData){
        return dictDataService.saveOrDictData(dictData);
    }
    /**
     * 删除数据 批量删除类型数据
     */
    @DeleteMapping("delDictData/{dictCodes}")
    @Log(title = "删除字典类型数据",business_type = "3")
    public Result<Boolean> delDictData(@PathVariable Long[] dictCodes){
        return dictDataService.delDictData(dictCodes);
    }
}
